package com.action.systemAction;

import java.util.HashMap;

import org.apache.struts.action.ActionForward;

import com.biz.systembiz.UsersBiz;

import base.Power;

import admin.mode.AdminMode;
import admin.mode.MemberDispatchAction;

public class UsersAction extends MemberDispatchAction {
	UsersBiz biz = new UsersBiz();

	// /UsersAction.do?opt=usersList
	// 列表显示
	public ActionForward usersList(Power power, AdminMode admin)
			throws Exception {
		power.setAttribute("roleList", biz.userList(power, admin));
		power.setAttribute("user", admin.getUserInfo());
		return power.findForward("/page/system/userList.jsp", false);
	}

	// /UsersAction.do?opt=user_delete
	// 删除用户
	public ActionForward user_delete(Power power, AdminMode admin)
			throws Exception {
		if (biz.delUser(power, admin, power.getParameter("ids"))) {
			power.setAttribute("message", "删除成功");
		}
		usersList(power, admin);
		return power.findForward("/page/system/userList.jsp", false);
	}

	// /UsersAction.do?opt=user_delete
	// 删除多个用户
	public ActionForward user_group_delete(Power power, AdminMode admin)
			throws Exception {
		if (biz.delGroupUser(power, admin)) {
			power.setAttribute("message", "删除成功");
		}
		usersList(power, admin);
		return power.findForward("/page/system/userList.jsp", false);
	}

	// /UsersAction.do?opt=user_add
	// 增加用户
	public ActionForward user_add(Power power, AdminMode admin)
			throws Exception {
		usersList(power, admin);
		return power.findForward("/page/system/userList.jsp", false);
	}

	// /UsersAction.do?opt=user_edit
	// 修改用户（赋予权限）
	public ActionForward user_edit(Power power, AdminMode admin)
			throws Exception {
		biz.updateUser(power, admin, power.getParameter("role_id"));
		usersList(power, admin);
		return power.findForward("/page/system/userList.jsp", false);
	}

	// /UsersAction.do?opt=user_edit
	// 修改用户（查看权限）
	public ActionForward user_info(Power power, AdminMode admin)
			throws Exception {
		HashMap<String, Object> map = biz.userInfo(power, power
				.getParameter("id"));
		power.setAttribute("infoList", map.get("infolist"));
		power.setAttribute("role", map.get("userinfo"));
		return power.findForward("/page/system/editUser.jsp", false);
	}

	// /UsersAction.do?opt=password_edit
	// 密码修改
	public ActionForward password_edit(Power power, AdminMode admin)
			throws Exception {
		return power.findForward("/page/system/userList.jsp", false);
	}
}
